package com.maycari.captainbi.common.bo;


import com.maycari.captainbi.common.constant.BaseConstant;
import com.maycari.tool.constant.BladeConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;


@ApiModel(description = "返回信息")
@Data
public class TtxtResult<T> implements Serializable {

    @ApiModelProperty(value = "状态码", required = true)
    private Integer code;

    @ApiModelProperty(value = "总数")
    private Integer count;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "承载数据")
    private T data;

    private PrintOperation printOperation;

    private List<PrintOperation> printOperationList;

    public TtxtResult(Integer code) {
        this.code = code;
    }

    public TtxtResult(Integer code, String msg) {
        this.code = code;
        this.message = msg;
    }

    private TtxtResult(int code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.message = msg;
    }

    /**
     * 返回TtxtResult
     *
     * @param <T> T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> success() {
        return data(null, BladeConstant.DEFAULT_SUCCESS_MESSAGE);
    }


    /**
     * 返回TtxtResult
     *
     * @param data 数据
     * @param <T>  T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> data(T data) {
        return data(data, BladeConstant.DEFAULT_SUCCESS_MESSAGE);
    }


    /**
     * 返回TtxtResult
     *
     * @param data 数据
     * @param msg  消息
     * @param <T>  T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> data(T data, String msg) {
        return data(BaseConstant.SUCCESS, data, msg);
    }

    /**
     * 返回TtxtResult
     *
     * @param code 状态码
     * @param data 数据
     * @param msg  消息
     * @param <T>  T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> data(int code, T data, String msg) {
        return new TtxtResult<>(code, data, data == null ? BladeConstant.DEFAULT_NULL_MESSAGE : msg);
    }

    /**
     * 返回TtxtResult
     *
     * @param msg 消息
     * @param <T> T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> fail(String msg) {
        return new TtxtResult<>(BaseConstant.FAILED, msg);
    }

    /**
     * 返回TtxtResult
     *
     * @param data 消息
     * @param <T>  T 泛型标记
     * @return TtxtResult
     */
    public static <T> TtxtResult<T> fail(T data) {
        return new TtxtResult<>(BaseConstant.FAILED, data, null);
    }

}
